<?php

class LoginController extends BaseController {

	public function login() {
		$data['status'] = Input::get('status');
		return View::make('admin.login', $data);
	}

	public function showLogin() {
		// show the form
		return View::make('admin/login');
	}
	
	

	public function doLogin() {
		// $y = 0;
		// for ($i = 0; $i < 10000000; $i++) {
			// $y++;
		// }
		// echo '0';
		// validate the info, create rules for the inputs
		$rules = array(
			'username'    => 'required|alphaNum|min:3',
			'password' => 'required|alphaNum|min:3'
		);
	
		// run the validation rules on the inputs from the form
		$validator = Validator::make(Input::all(), $rules);
	
		// if the validator fails, redirect back to the form
		if ($validator->fails()) {
			//return Redirect::to('login')->withErrors($validator);
			echo '0';
		} else {
	
			// do the validation
			if (Auth::attempt(array('username' => Input::get('username'), 'password' => Input::get('password')))) {
				// validation successful!
				// redirect them to the secure section or whatever
				// return Redirect::to('secure');
	
				// for now we'll just echo success (even though echoing in a controller is bad)
				echo '1';
			} else {
				// validation not successful, send back to form
				echo '0';
			}
	
		}
	}

}
